/**
 * 客户黑名单 - 编辑页面
 * @author miaoyl
 * @date 2018/01/09
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: {
                GWAKL004: null,
                GWAKORIG_NAME: null
            },
            rules: {
                GWBZ001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBZ002: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBZACTI: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions:{
                sys_y_n:app.datas_("sys_y_n"),
                crm_gwai306_gwbz002:app.datas_("crm_gwai306_gwbz002")
            },
        },
        callObj,
        pageVue,
        layOpenIndex
    ;

    var Gwai306Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai306_edit',
                _loadTplsFull: [
                    {
                        dom: 'common_open_window', tpl: 'common/_open_window'
                    }
                ]
            }, win);
        },

        editData: function () {
            app.ajax({
                xurl: 'crm/gwai306/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: '客户黑名单修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        app.pageModule('gwai306').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },

        addData: function () {
            app.ajax({
                xurl: 'crm/gwai306/add',
                xdata: vueData.form,
                loading: true,
                okmsg: '客户黑名单保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwai306').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },

        _call: function (obj) {
            pageVue.$refs['form'].resetFields();
            layOpenIndex = obj.layOpenIndex;
            if(obj.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (obj.is_add) {
                vueData.isAdd=true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWBZACTI:'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                callObj = obj.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['GWBZ_T'], vueData.form);
            pageVue = new Vue({
                el: '#gwai306_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addData();
                                } else {
                                    self.editData();
                                }
                            }
                        });
                    },
                    openGwbz001: function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_gwak001',
                                    columnList: [
                                        {label: '客户编号', prop: 'GWAK001', width: '200'},
                                        {label: '名称', prop: 'GWAKL004', width: '200'},
                                        {label: '归属组织', prop: 'GWAKORIG_NAME', width: '200'},
                                    ]
                                },
                                cb: function (data) {
                                    vueData.form.GWBZ001 = data.GWAK001;
                                    vueData.form.GWAKL004 = data.GWAKL004;
                                    vueData.form.GWBZORIG = data.GWAKORIG;
                                    vueData.form.GWBZORIG_NAME = data.GWAKORIG_NAME;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择客户编号',
                                area: ['600px', '470px']
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('gwai306_edit');
                }
            });
        },

        _lazy: function () {
            this._super();
        }
    });

    return new Gwai306Edit();

});
